﻿@{
    ViewBag.Title = this.Context.Request.QueryString["title"];
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/Scripts/swfupload")
    <script type="text/javascript">

        //挂接ExtJS准备完毕事件
        Ext.onReady
        (
            function ()
            {
                //初始化快速提示
                Ext.QuickTips.init();

                //设置状态保存提供者（当前设置为Cookie）
                Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', { path: _StatePath }));

                //用于记录当前记录
                var _CurrentRecord = undefined;

                //创建数据存储对象
                var store = Ext.create
                (
                    'Ext.data.Store',
                    {
                        pageSize: 20,
                        autoSync: false,
                        autoLoad: false,
                        root: 'data',
                        remoteFilter: true,
                        remoteSort: true,
                        sorters: [{ property: 'LoginName', direction: 'ASC' }],
                        model: 'Account',
                        listeners:
                        {
                            //处理数据加载事件
                            load: function (store, records, successful, eOpts)
                            {
                                //获得当前选中行
                                var models = grid.getSelectionModel().getSelection();

                                //判断是否选中数据
                                if (models.length > 0)
                                {
                                    //设置当前选中记录
                                    _CurrentRecord = store.getById(models[0].getId());
                                }
                                else
                                {
                                    //设置当前选中记录
                                    _CurrentRecord = null;
                                }

                                //更新按钮状态
                                UpdateButtonState(_CurrentRecord);
                            }
                        },
                        proxy:
                        {
                            type: 'ajax',
                            batchActions: false,
                            url: spms.url.Action('List', 'Account'),
                            reader:
                            {
                                type: 'json',
                                root: 'data'
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建角色数据存储对象
                var role_store = Ext.create
                (
                    'Ext.data.Store',
                    {
                        pageSize: 0,
                        autoSync: false,
                        autoLoad: false,
                        root: 'data',
                        remoteFilter: true,
                        remoteSort: false,
                        sorters: [{ property: 'Role_Title', direction: 'ASC' }],
                        filters: [{ property: 'IsEnabled@E', value: true }],
                        model: 'Role',
                        proxy:
                        {
                            type: 'ajax',
                            batchActions: false,
                            url: spms.url.Action('UserRoles', 'Account'),
                            reader:
                            {
                                type: 'json',
                                root: 'data'
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建组织结构存储对象
                var organization_store = Ext.create
                (
                    'Ext.data.TreeStore',
                    {
                        pageSize: 0,
                        autoSync: false,
                        autoLoad: true,
                        remoteFilter: true,
                        remoteSort: false,
                        folderSort: false,
                        clearOnLoad: true,
                        model: 'Organization',
                        root:
                        {
                            expanded: true
                        },
                        proxy:
                        {
                            type: 'ajax',
                            model: 'Organization',
                            batchActions: false,
                            url: spms.url.Action('List', 'Organization'),
                            reader:
                            {
                                type: 'json',
                                root: 'children',
                                implicitIncludes: true
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建工具栏
                var toolbar = Ext.create
                (
                    'Ext.toolbar.Toolbar',
                    {
                        region: 'north',
                        layout: 'hbox',
                        border: 5,
                        height: 32,
                        border: '1 0 1 0',
                        margins: '0 0 0 0',
                        padding: '0 6 0 6',
                        items:
                        [
                            {
                                id: 'spms-cmd-refresh',
                                text: '刷新',
                                tooltip: '重新加载数据',
                                tooltipType: 'qtip',
                                iconCls: 'spms-icon-refresh',
                                cls: 'spms-page-menu-button',
                                listeners:
                                {
                                    click: OnRefresh
                                }
                            },
                            '-',
                            {
                                id: 'spms-cmd-add',
                                text: '新增',
                                tooltip: '新增账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-add',
                                listeners:
                                {
                                    click: OnAdd
                                }
                            },
                            {
                                id: 'spms-cmd-remove',
                                text: '删除',
                                tooltip: '删除选中的账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-delete',
                                disabled: true,
                                listeners:
                                {
                                    click: OnRemove
                                }
                            },
                            {
                                id: 'spms-cmd-edit',
                                text: '编辑',
                                tooltip: '编辑选中的账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-edit',
                                disabled: true,
                                listeners:
                                {
                                    click: OnEdit
                                }
                            },
                            '-',
                            {
                                id: 'spms-cmd-authorize',
                                text: '授权',
                                tooltip: '设置选中账户的权限设定',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-authorize',
                                disabled: true,
                                listeners:
                                {
                                    click: OnAuthorize
                                }
                            },
                            '->',
                            {
                                id: 'spms-cmd-state',
                                text: '停用',
                                tooltip: '停用选中的账户',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-disabled',
                                disabled: true,
                                listeners:
                                {
                                    click: OnChangeState
                                }
                            },
                            {
                                id: 'spms-cmd-unlock',
                                text: '解锁',
                                tooltip: '解除选中账户的锁定状态',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-unlock',
                                disabled: true,
                                listeners:
                                {
                                    click: OnUnlock
                                }
                            },
                            {
                                id: 'spms-cmd-resetpassword',
                                text: '重置密码',
                                tooltip: '重置选中账户的登录密码',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-reset',
                                disabled: true,
                                listeners:
                                {
                                    click: OnResetPassword
                                }
                            }
                        ]
                    }
                );

                //创建检索面板
                var search = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'north',
                        frame: false,
                        animCollapse: false,
                        iconCls: 'spms-icon-search',
                        stateful: true,
                        stateId: 'spms-account-search-state',
                        collapsible: true,
                        collapseMode: 'header',
                        titleCollapse: true,
                        collapsed: true,
                        margin: '0 0 6 0',
                        layout: 'fit',
                        id: 'spms-panel-search',
                        cls: 'spms-page-card-detail',
                        border: true,
                        title: '检索',
                        listeners:
                        {
                            //挂接显示事件
                            show: function (win, options)
                            {
                                //获得表单
                                var form = win.down('form');

                                //判断是否存在
                                if (form)
                                {
                                    //重置内容
                                    form.getForm().reset();

                                    //设置焦点
                                    form.down('field').focus(false, 50);
                                }
                            }
                        },
                        items:
                        [
                            {
                                xtype: 'form',
                                frame: false,
                                autoScroll: true,
                                bodyPadding: 6,
                                bodyCls: 'spms-page-card-detail-form-body',
                                bodyBorder: false,
                                border: false,
                                layout:
                                {
                                    type: 'table',
                                    columns: 2,
                                    tableAttrs:
                                    {
                                        style:
                                        {
                                            width: '100%'
                                        },
                                        cellpadding: 6
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                maxLength: 20,
                                                xtype: 'checkbox',
                                                boxLabel: '账户名称:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkLoginName',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'LoginName',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                maxLength: 20,
                                                xtype: 'checkbox',
                                                boxLabel: '职员姓名:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkEmployeeName',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'EmployeeName',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                xtype: 'checkbox',
                                                boxLabel: '是否启用:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkIsEnabled',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                xtype: 'radiogroup',
                                                itemId: 'IsEnabled',
                                                width: 190,
                                                columns: 3,
                                                items:
                                                [
                                                    { boxLabel: '全部', name: 'IsEnabled' },
                                                    { boxLabel: '已启用', name: 'IsEnabled', inputValue: true, checked: true },
                                                    { boxLabel: '未启用', name: 'IsEnabled', inputValue: false }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                xtype: 'checkbox',
                                                boxLabel: '是否授权:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkIsAuthorized',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                xtype: 'radiogroup',
                                                itemId: 'IsAuthorized',
                                                width: 190,
                                                columns: 3,
                                                items:
                                                [
                                                    { boxLabel: '全部', name: 'IsAuthorized', inputValue: null },
                                                    { boxLabel: '已授权', name: 'IsAuthorized', inputValue: true, checked: true },
                                                    { boxLabel: '未授权', name: 'IsAuthorized', inputValue: false }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 80,
                                                xtype: 'checkbox',
                                                boxLabel: '是否锁定:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkIsLocked',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                xtype: 'radiogroup',
                                                itemId: 'IsLocked',
                                                width: 190,
                                                columns: 3,
                                                items:
                                                [
                                                    { boxLabel: '全部', name: 'IsLocked', inputValue: null },
                                                    { boxLabel: '已锁定', name: 'IsLocked', inputValue: true, checked: true },
                                                    { boxLabel: '未锁定', name: 'IsLocked', inputValue: false }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                dockedItems:
                                [
                                    {
                                        xtype: 'toolbar',
                                        dock: 'bottom',
                                        ui: 'footer',
                                        cls: 'spms-page-card-toolbar',
                                        padding: '0 6 12 0',
                                        items:
                                        [
                                            '->',
                                            {
                                                text: '检索',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function ()
                                                {
                                                    //获得当前对象
                                                    var me = this;

                                                    //获得表单对象
                                                    var form = me.up('form');

                                                    //检查数据是否合法
                                                    if (form.getForm().isValid())
                                                    {
                                                        //清除过滤条件
                                                        store.filters.clear();

                                                        //生成过滤条件
                                                        var filters = new Array();

                                                        //判断是否以账户名称检索
                                                        if (form.down('#chkLoginName').getValue())
                                                        {
                                                            //添加检索条件
                                                            filters.push({ property: 'LoginName@C', value: form.down('#LoginName').getValue() });
                                                        }

                                                        //判断是否以职员名检索
                                                        if (form.down('#chkEmployeeName').getValue())
                                                        {
                                                            //添加检索条件
                                                            filters.push({ property: 'EmployeeName@C', value: form.down('#EmployeeName').getValue() });
                                                        }

                                                        //判断是否以启用状态检索
                                                        if (form.down('#chkIsEnabled').getValue())
                                                        {
                                                            //获得选择值
                                                            var value = form.down('#IsEnabled').getValue()['IsEnabled'];

                                                            //判断是否设定值
                                                            if (value != null)
                                                            {
                                                                //添加检索条件
                                                                filters.push({ property: 'IsEnabled@E', value: value });
                                                            }
                                                        }

                                                        //判断是否以启授权状态检索
                                                        if (form.down('#chkIsAuthorized').getValue())
                                                        {
                                                            //获得选择值
                                                            var value = form.down('#IsAuthorized').getValue()['IsAuthorized'];

                                                            //判断是否设定值
                                                            if (value != null)
                                                            {
                                                                //添加检索条件
                                                                filters.push({ property: 'IsAuthorized@E', value: value });
                                                            }
                                                        }

                                                        //判断是否以锁定状态检索
                                                        if (form.down('#chkIsLocked').getValue())
                                                        {
                                                            //获得选择值
                                                            var value = form.down('#IsLocked').getValue()['IsLocked'];

                                                            //判断是否设定值
                                                            if (value != null)
                                                            {
                                                                //添加检索条件
                                                                filters.push({ property: 'IsLocked@E', value: value });
                                                            }
                                                        }

                                                        //刷新数据
                                                        Refresh({ filters: filters });
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                );

                //创建表格
                var grid = Ext.create
                (
                    'Ext.grid.Panel',
                    {
                        region: 'center',
                        store: store,
                        stateful: true,
                        border: true,
                        cls: 'spms-grid',
                        stateId: 'spms-account-grid-state',
                        id: 'spms-card-grid',
                        forceFit: true,
                        autoScroll: true,
                        columnLines: true,
                        enableLocking: false,
                        unlockText: spms.resources.text_grid_column_unlock,
                        lockText: spms.resources.text_grid_column_lock,
                        viewConfig:
                        {
                            stripeRows: true,
                            loadingText: spms.resources.text_loading,
                            singleSelect: true
                        },
                        bbar: Ext.create
                            (
                            'SPMS.PagingToolbar',
                            {
                                store: store
                            }
                        ),
                        listeners:
                        {
                            select: OnRowSelect
                        },
                        columns:
                        [
                            {
                                text: '账户名称',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'LoginName',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '是否启用',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'IsEnabled',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '是否授权',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'IsAuthorized',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '是否锁定',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'IsLocked',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '重置密码',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'MustChangePassword',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '内置账户',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'IsBuildin',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '最后登录时间',
                                width: 140,
                                minWidth: 140,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'LastLoginTime',
                                renderer: Ext.util.Format.dateRenderer('Y/m/d H:i:s'),
                                hideable: true
                            },
                            {
                                text: '职员姓名',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'EmployeeName',
                                hideable: true
                            },
                            {
                                text: '数字签名',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'center',
                                dataIndex: 'HasSignature',
                                renderer: spms.format.booleanRenderer,
                                hideable: true
                            },
                            {
                                text: '所属单位',
                                width: 120,
                                minWidth: 80,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'Organization',
                                hideable: true
                            },
                            {
                                text: '职务',
                                width: 80,
                                minWidth: 80,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'Title',
                                hideable: true
                            },
                            {
                                text: '联系电话',
                                width: 120,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'PhoneNumber1',
                                hideable: true
                            },
                            {
                                text: '联系电话',
                                width: 120,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'PhoneNumber2',
                                hideable: true
                            },
                            {
                                text: '电子邮箱',
                                width: 240,
                                minWidth: 120,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'Email',
                                hideable: true
                            },
                            {
                                text: '备注',
                                width: 240,
                                minWidth: 240,
                                sortable: false,
                                align: 'left',
                                dataIndex: 'Memo',
                                hideable: true,
                                flex: 1
                            }
                        ]
                    }
                );

                //创建布局
                var card = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'center',
                        layout: 'card',
                        border: false,
                        defaults:
                        {
                            border: false
                        },
                        bodyStyle: 'padding:6px',
                        items:
                        [
                            {
                                xtype: 'panel',
                                id: 'spms-card-list',
                                layout: 'border',
                                items:
                                [
                                    search,
                                    grid
                                ]
                            }
                        ]
                    }
                );

                //创建视口
                var viewport = Ext.create
                (
                    'Ext.container.Viewport',
                    {
                        layout: 'border',
                        items:
                        [
                            {
                                region: 'north',
                                contentEl: 'spms-page-title',
                                border: false,
                                height: 48,
                                margins: '0 0 0 0'
                            },
                            toolbar,
                            card
                        ]
                    }
                );

                //加载数据
                store.load();

                //更新按钮状态
                function UpdateButtonState(record)
                {
                    //判断是否选中记录
                    if (record)
                    {
                        //设置删除按钮状态
                        spms.common.SetDisabled('spms-cmd-remove', record.get('IsBuildin'));
                        //设置编辑按钮状态
                        spms.common.SetEnabled('spms-cmd-edit', true);
                        //设置授权按钮状态
                        spms.common.SetEnabled('spms-cmd-authorize', true);
                        //设置停用按钮状态
                        spms.common.SetEnabled('spms-cmd-state', true);
                        spms.common.ApplyIIf('spms-cmd-state', record.get('IsEnabled'), { text: '停用', tooltip: '停用选中的账户', iconCls: 'spms-icon-disabled' }, { text: '启用', tooltip: '启用选中的账户', iconCls: 'spms-icon-enabled' });
                        //设置解锁按钮状态
                        spms.common.SetEnabled('spms-cmd-unlock', record.get('IsLocked'));
                        //设置重置密码按钮状态
                        spms.common.SetEnabled('spms-cmd-resetpassword', true);
                    }
                    else
                    {
                        //设置删除按钮状态
                        spms.common.SetEnabled('spms-cmd-remove', false);
                        //设置编辑按钮状态
                        spms.common.SetEnabled('spms-cmd-edit', false);
                        //设置授权按钮状态
                        spms.common.SetEnabled('spms-cmd-authorize', false);
                        //设置停用按钮状态
                        spms.common.SetEnabled('spms-cmd-state', false);
                        //设置解锁按钮状态
                        spms.common.SetEnabled('spms-cmd-unlock', false);
                        //设置重置密码按钮状态
                        spms.common.SetEnabled('spms-cmd-resetpassword', false);
                    }
                }

                //处理刷新按钮点击事件
                function OnRefresh(sender)
                {
                    //刷新数据
                    Refresh();
                }

                //处理新增按钮点击事件
                function OnAdd(sender)
                {
                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Create == 'undefined')
                    {
                        //创建角色存储
                        me._Role_Store = Ext.create
                        (
                            'Ext.data.Store',
                            {
                                pageSize: 0,
                                autoSync: false,
                                autoLoad: true,
                                root: 'data',
                                remoteFilter: true,
                                remoteSort: false,
                                sorters: [{ property: 'Role_Title', direction: 'ASC' }],
                                model: 'Role',
                                proxy:
                                {
                                    type: 'ajax',
                                    batchActions: false,
                                    url: spms.url.Action('List', 'Role'),
                                    reader:
                                    {
                                        type: 'json',
                                        root: 'data'
                                    },
                                    listeners:
                                    {
                                        //处理代理异常
                                        exception: spms.exception.HandleProxyError
                                    }
                                }
                            }
                        );

                        //创建新增面板
                        me._Panel_Create = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'border',
                                id: 'spms-card-create',
                                cls: 'spms-page-card-detail',
                                border: false,
                                header:
                                {
                                    title: '新增账户',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                listeners:
                                {
                                    //挂接显示事件
                                    show: function (win, options)
                                    {
                                        //获得表单
                                        var form = win.down('form');

                                        //判断是否存在
                                        if (form)
                                        {
                                            //获得窗体
                                            form.getForm().reset();

                                            //设置焦点
                                            form.down('field').focus(false, 50);
                                        }
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'form',
                                        region: 'center',
                                        autoScroll: true,
                                        frame: false,
                                        method: 'POST',
                                        waitMsgTarget: true,
                                        waitTitle: spms.resources.text_app_title,
                                        bodyPadding: 12,
                                        bodyCls: 'spms-page-card-detail-form-body',
                                        bodyBorder: false,
                                        border: false,
                                        defaultType: 'textfield',
                                        fieldDefaults:
                                        {
                                            labelAlign: 'left',
                                            labelWidth: 72,
                                            anchor: '100%',
                                            msgTarget: 'qtip'
                                        },
                                        items:
                                        [
                                            {
                                                xtype: 'textfield',
                                                name: 'LoginName',
                                                maxLength: 40,
                                                minLength: 4,
                                                fieldLabel: '账户名称',
                                                emptyText: '账户的登录名称',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'treecombobox',
                                                name: 'Organization_ID',
                                                inputType: 'text',
                                                fieldLabel: '所属单位',
                                                emptyText: '所属单位',
                                                pickerCls: 'spms-grid spms-dropdown',
                                                pickerRootVisible: false,
                                                pickerUseArrows: true,
                                                pickerColumnLines: false,
                                                pickerRowLines: false,
                                                store: organization_store,
                                                allowBlank: false,
                                                editable: true,
                                                disabled: false,
                                                displayField: 'text'
                                            },
                                            {
                                                xtype: 'checkbox',
                                                name: 'IsEnabled',
                                                fieldLabel: '是否启用',
                                                checked: true,
                                                disabled: false,
                                                inputValue: true
                                            },
                                            {
                                                xtype: 'checkbox',
                                                name: 'IsAuthorized',
                                                fieldLabel: '是否授权',
                                                checked: true,
                                                disabled: false,
                                                inputValue: true
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'EmployeeName',
                                                maxLength: 40,
                                                fieldLabel: '职员姓名',
                                                emptyText: '职员姓名',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Title',
                                                maxLength: 20,
                                                fieldLabel: '职　　务',
                                                emptyText: '职务',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Department',
                                                maxLength: 20,
                                                cls: 'Test',
                                                fieldLabel: '部　　门',
                                                emptyText: '部门',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'PhoneNumber1',
                                                maxLength: 20,
                                                fieldLabel: '联系电话',
                                                emptyText: '联系电话',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'PhoneNumber2',
                                                maxLength: 20,
                                                fieldLabel: '联系电话',
                                                emptyText: '联系电话',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Email',
                                                maxLength: 100,
                                                fieldLabel: '电子信箱',
                                                emptyText: '电子信箱',
                                                allowBlank: true,
                                                disabled: false,
                                                vtype: 'email'
                                            },
                                            {
                                                xtype: 'textareafield',
                                                name: 'Memo',
                                                fieldLabel: '备　　注',
                                                emptyText: '备注信息（最长400个字符）',
                                                maxLength: 400,
                                                height: 72,
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'HasSignature',
                                                itemId: 'HasSignature'
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'Signature_ID',
                                                itemId: 'Signature_ID'
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                fieldLabel: '所属角色',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout: 'fit',
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'grid',
                                                        height: 240,
                                                        store: me._Role_Store,
                                                        draggable: false,
                                                        stateful: false,
                                                        cls: 'spms-grid',
                                                        border: true,
                                                        forceFit: true,
                                                        autoScroll: true,
                                                        columnLines: true,
                                                        viewConfig:
                                                        {
                                                            stripeRows: true,
                                                            loadingText: spms.resources.text_loading,
                                                            singleSelect: true
                                                        },
                                                        columns:
                                                        [
                                                            {
                                                                text: '是否授予',
                                                                width: 80,
                                                                minWidth: 80,
                                                                sortable: true,
                                                                xtype: 'checkcolumn',
                                                                dataIndex: 'IsAssigned',
                                                                hideable: false,
                                                                align: 'center'
                                                            },
                                                            {
                                                                text: '角色显示名',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Title',
                                                                hideable: false
                                                            },
                                                            {
                                                                text: '角色参照名',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Name',
                                                                hideable: false
                                                            },
                                                            {
                                                                text: '角色说明',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Desc',
                                                                hideable: false,
                                                                flex: 1
                                                            }
                                                        ]
                                                    }
                                                ]
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                width: '100%',
                                                fieldLabel: '签名图片',
                                                layout:
                                                {
                                                    type: 'hbox',
                                                    align: 'stretch'
                                                },
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'panel',
                                                        border: 1,
                                                        width: 192,
                                                        height: 128,
                                                        bodyCls: 'spms-image-preview',
                                                        items:
                                                        [
                                                            {
                                                                xtype: 'image',
                                                                itemId: 'SignaturePreview',
                                                                maxWidth: 192,
                                                                maxHeight: 128
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        xtype: 'panel',
                                                        border: false,
                                                        padding: '33 12 33 12',
                                                        layout:
                                                        {
                                                            type: 'vbox',
                                                            align: 'center'
                                                        },
                                                        items:
                                                        [
                                                            {
                                                                xtype: 'button',
                                                                iconCls: 'spms-icon-upload',
                                                                tooltip: '上传签名图片',
                                                                width: 25,
                                                                height: 25,
                                                                margin: '0 0 12 0',
                                                                handler: function ()
                                                                {
                                                                    //上传文件
                                                                    UploadFile(me._Panel_Create);
                                                                }
                                                            },
                                                            {
                                                                xtype: 'button',
                                                                iconCls: 'spms-icon-delete',
                                                                tooltip: '删除签名图片',
                                                                width: 25,
                                                                height: 25
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ],
                                        dockedItems:
                                        [
                                            {
                                                xtype: 'toolbar',
                                                dock: 'bottom',
                                                ui: 'footer',
                                                cls: 'spms-page-card-detail-toolbar',
                                                padding: '15 0 3 0',
                                                items:
                                                [
                                                    '->',
                                                    {
                                                        text: '连续新增',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function ()
                                                        {
                                                            //执行新增操作
                                                            DoAdd.call(me, true);
                                                        }
                                                    },

                                                    {
                                                        text: '新增',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function ()
                                                        {
                                                            //执行新增操作
                                                            DoAdd.call(me, false);
                                                        }
                                                    },
                                                    {
                                                        text: '取消',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function ()
                                                        {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        );

                        //添加到面板
                        card.add(me._Panel_Create);
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-create');
                }

                //处理删除按钮点击事件
                function OnRemove(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        return;
                    }

                    //询问是否确定删除
                    Ext.Msg.show
                    (
                        {
                            title: spms.resources.text_app_title,
                            msg: '确定要删除选中的账户"' + _CurrentRecord.get('LoginName') + '"吗?',
                            buttons: Ext.Msg.YESNO,
                            icon: Ext.Msg.QUESTION,
                            autoScroll: true,
                            closeAction: 'destroy',
                            fn: function (button, text, eOpts)
                            {
                                //判断是否确定删除 
                                if (button == 'yes')
                                {
                                    //显示加载
                                    grid.setLoading(spms.resources.text_submitting);

                                    //创建请求对象
                                    Ext.Ajax.request
                                    (
                                        {
                                            url: spms.url.Action('Delete', 'Account'),
                                            method: spms.constant.HttpMethod.POST,
                                            jsonData: _CurrentRecord.data,
                                            callback: function (options, success, response)
                                            {
                                                //隐藏加载
                                                grid.setLoading(false);

                                                //处理错误
                                                if (spms.exception.HandleAjaxRequestError(options, success, response))
                                                {
                                                    //刷新数据
                                                    Refresh();
                                                }
                                            }
                                        }
                                    );
                                }
                            }
                        }
                    );
                }

                //处理编辑按钮点击事件
                function OnEdit(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        //如果没有选中记录，则直接返回
                        return;
                    }

                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Edit == 'undefined')
                    {
                        //创建新增面板
                        me._Panel_Edit = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'fit',
                                id: 'spms-card-edit',
                                cls: 'spms-page-card-detail',
                                border: false,
                                header:
                                {
                                    title: '编辑账户',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                listeners:
                                {
                                    //挂接显示事件
                                    show: function (panel, options)
                                    {
                                        //获得面板
                                        var panel = me._Panel_Edit;

                                        //获得表单
                                        var form = panel.down('form');

                                        //获得预览面板
                                        var panelSignaturePreview = panel.down('#SignaturePreview');

                                        //判断是否存在
                                        if (spms.common.IsValid(form))
                                        {
                                            //重置内容
                                            form.getForm().reset();

                                            //判断是否有效
                                            if (spms.common.IsValid(panelSignaturePreview))
                                            {
                                                //显示预览图
                                                panelSignaturePreview.setSrc(Ext.BLANK_IMAGE_URL);
                                            }

                                            //提交数据
                                            form.load
                                            (
                                                {
                                                    url: spms.url.Action('Detail', 'Account'),
                                                    method: spms.constant.HttpMethod.Get,
                                                    params: { User_ID: _CurrentRecord.get('User_ID'), LoginName: _CurrentRecord.get('LoginName') },
                                                    waitTitle: spms.resources.text_loading_title,
                                                    waitMsg: spms.resources.text_loading,
                                                    success: function (panel, action)
                                                    {
                                                        //处理错误
                                                        if (spms.exception.HandleSuccessError(panel, action))
                                                        {
                                                            //判断是否有预览图片
                                                            var txtHasSignature = form.down('#HasSignature');

                                                            //判断是否有效
                                                            if (spms.common.IsValid(txtHasSignature))
                                                            {
                                                                //判断是否有签名图
                                                                if (txtHasSignature.getValue() == 'true')
                                                                {
                                                                    //用于保存参数
                                                                    var params =
                                                                    [
                                                                        { Name: 'User_ID', Value: _CurrentRecord.get('User_ID') }
                                                                    ];

                                                                    //获得图片地址
                                                                    var imageUrl = spms.url.Action('GetSignatureImage', 'Account', params);

                                                                    //显示预览图
                                                                    panelSignaturePreview.setSrc(imageUrl);
                                                                }
                                                            }

                                                            //设置焦点
                                                            form.down('field').focus(false, 100);
                                                        }
                                                        else
                                                        {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    },
                                                    failure: function (form, action)
                                                    {
                                                        //处理错误
                                                        spms.exception.HandleFailureError(form, action);

                                                        //启用工具栏
                                                        toolbar.setDisabled(false);

                                                        //返回一览标签
                                                        card.getLayout().setActiveItem('spms-card-list');
                                                    }
                                                }
                                            );
                                        }
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'form',
                                        autoScroll: true,
                                        frame: false,
                                        method: 'POST',
                                        waitMsgTarget: true,
                                        waitTitle: spms.resources.text_app_title,
                                        bodyPadding: 12,
                                        bodyCls: 'spms-page-card-detail-form-body',
                                        bodyBorder: false,
                                        border: false,
                                        defaultType: 'textfield',
                                        fieldDefaults:
                                        {
                                            labelAlign: 'left',
                                            labelWidth: 72,
                                            anchor: '100%',
                                            msgTarget: 'qtip'
                                        },
                                        items:
                                        [
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'User_ID'
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'LoginName',
                                                maxLength: 40,
                                                minLength: 4,
                                                fieldLabel: '账户名称',
                                                emptyText: '账户的登录名称',
                                                allowBlank: false,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'treecombobox',
                                                name: 'Organization_ID',
                                                inputType: 'text',
                                                fieldLabel: '所属单位',
                                                emptyText: '所属单位',
                                                pickerCls: 'spms-grid spms-dropdown',
                                                pickerRootVisible: false,
                                                pickerUseArrows: true,
                                                pickerColumnLines: false,
                                                pickerRowLines: false,
                                                store: organization_store,
                                                allowBlank: false,
                                                editable: true,
                                                disabled: false,
                                                displayField: 'text'
                                            },
                                            {
                                                xtype: 'checkbox',
                                                name: 'IsEnabled',
                                                fieldLabel: '是否启用',
                                                disabled: false,
                                                inputValue: true
                                            },
                                            {
                                                xtype: 'checkbox',
                                                name: 'IsAuthorized',
                                                fieldLabel: '是否授权',
                                                disabled: false,
                                                inputValue: true
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'EmployeeName',
                                                maxLength: 40,
                                                fieldLabel: '职员姓名',
                                                emptyText: '职员姓名',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Title',
                                                maxLength: 20,
                                                fieldLabel: '职　　务',
                                                emptyText: '职务',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'PhoneNumber1',
                                                maxLength: 20,
                                                fieldLabel: '联系电话',
                                                emptyText: '联系电话',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'PhoneNumber2',
                                                maxLength: 20,
                                                fieldLabel: '联系电话',
                                                emptyText: '联系电话',
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'textfield',
                                                name: 'Email',
                                                maxLength: 100,
                                                fieldLabel: '电子信箱',
                                                emptyText: '电子信箱',
                                                allowBlank: true,
                                                disabled: false,
                                                vtype: 'email'
                                            },
                                            {
                                                xtype: 'textareafield',
                                                name: 'Memo',
                                                fieldLabel: '备　　注',
                                                emptyText: '备注信息（最长400个字符）',
                                                maxLength: 400,
                                                height: 72,
                                                allowBlank: true,
                                                disabled: false
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'HasSignature',
                                                itemId: 'HasSignature'
                                            },
                                            {
                                                xtype: 'hiddenfield',
                                                name: 'Signature_ID',
                                                itemId: 'Signature_ID'
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                fieldLabel: '所属角色',
                                                width: '100%',
                                                defaultType: 'textfield',
                                                layout: 'fit',
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'grid',
                                                        height: 240,
                                                        store: role_store,
                                                        draggable: false,
                                                        stateful: false,
                                                        cls: 'spms-grid',
                                                        border: true,
                                                        forceFit: true,
                                                        autoScroll: true,
                                                        columnLines: true,
                                                        viewConfig:
                                                        {
                                                            stripeRows: true,
                                                            loadingText: spms.resources.text_loading,
                                                            singleSelect: true
                                                        },
                                                        columns:
                                                        [
                                                            {
                                                                text: '授予状态',
                                                                width: 80,
                                                                minWidth: 80,
                                                                sortable: true,
                                                                xtype: 'checkcolumn',
                                                                dataIndex: 'IsAssigned',
                                                                hideable: false,
                                                                align: 'center'
                                                            },
                                                            {
                                                                text: '角色显示名',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Title',
                                                                hideable: false
                                                            },
                                                            {
                                                                text: '角色参照名',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Name',
                                                                hideable: false
                                                            },
                                                            {
                                                                text: '角色说明',
                                                                width: 200,
                                                                minWidth: 120,
                                                                sortable: true,
                                                                align: 'left',
                                                                dataIndex: 'Role_Desc',
                                                                hideable: false,
                                                                flex: 1
                                                            }
                                                        ]
                                                    }
                                                ]
                                            },
                                            {
                                                xtype: 'fieldcontainer',
                                                width: '100%',
                                                fieldLabel: '签名图片',
                                                layout:
                                                {
                                                    type: 'hbox',
                                                    align: 'stretch'
                                                },
                                                padding: 0,
                                                border: 0,
                                                items:
                                                [
                                                    {
                                                        xtype: 'panel',
                                                        border: 1,
                                                        width: 192,
                                                        height: 128,
                                                        bodyCls: 'spms-image-preview',
                                                        items:
                                                        [
                                                            {
                                                                xtype: 'image',
                                                                itemId: 'SignaturePreview',
                                                                maxWidth: 192,
                                                                maxHeight: 128
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        xtype: 'panel',
                                                        border: false,
                                                        padding: '33 12 33 12',
                                                        layout:
                                                        {
                                                            type: 'vbox',
                                                            align: 'center'
                                                        },
                                                        items:
                                                        [
                                                            {
                                                                xtype: 'button',
                                                                iconCls: 'spms-icon-upload',
                                                                tooltip: '上传签名图片',
                                                                width: 25,
                                                                height: 25,
                                                                margin: '0 0 12 0',
                                                                handler: function ()
                                                                {
                                                                    //上传文件
                                                                    UploadFile(me._Panel_Edit);
                                                                }
                                                            },
                                                            {
                                                                xtype: 'button',
                                                                iconCls: 'spms-icon-delete',
                                                                tooltip: '删除签名图片',
                                                                width: 25,
                                                                height: 25
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ],
                                        dockedItems:
                                        [
                                            {
                                                xtype: 'toolbar',
                                                dock: 'bottom',
                                                ui: 'footer',
                                                cls: 'spms-page-card-detail-toolbar',
                                                padding: '15 0 3 0',
                                                items:
                                                [
                                                    '->',
                                                    {
                                                        text: '保存',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function ()
                                                        {
                                                            //获得表单
                                                            var form = me._Panel_Edit.down('form');

                                                            //获得存储对象
                                                            var roleStore = role_store;

                                                            //用于记录需要提交的数据
                                                            var postParams = [];

                                                            //循环收集需要提交的数据
                                                            for (var index = 0; index < roleStore.getCount() ; index++)
                                                            {
                                                                //获得记录
                                                                var model = roleStore.getAt(index);

                                                                //判断是否设置了权限
                                                                if (model.get('IsAssigned'))
                                                                {
                                                                    //添加模型
                                                                    postParams.push(model.get('Role_ID'));
                                                                }
                                                            }

                                                            //判断表单是否有效
                                                            if (form)
                                                            {
                                                                //获得表单对象
                                                                var formBase = form.getForm();

                                                                //检查数据是否合法
                                                                if (formBase.isValid())
                                                                {
                                                                    //提交数据
                                                                    formBase.submit
                                                                    (
                                                                        {
                                                                            url: spms.url.Action('Update', 'Account'),
                                                                            method: spms.constant.HttpMethod.Post,
                                                                            params: { Roles: postParams },
                                                                            submitEmptyText: false,
                                                                            waitTitle: spms.resources.text_submitting_title,
                                                                            waitMsg: spms.resources.text_submitting,
                                                                            success: function (panel, action)
                                                                            {
                                                                                //处理提交错误
                                                                                if (spms.exception.HandleSuccessError(panel, action))
                                                                                {
                                                                                    //启用工具栏
                                                                                    toolbar.setDisabled(false);

                                                                                    //返回一览标签
                                                                                    card.getLayout().setActiveItem('spms-card-list');

                                                                                    //刷新数据
                                                                                    Refresh();
                                                                                }
                                                                            },
                                                                            failure: spms.exception.HandleFailureError
                                                                        }
                                                                    );
                                                                }
                                                            }
                                                        }
                                                    },
                                                    {
                                                        text: '取消',
                                                        xtype: 'button',
                                                        cls: 'spms-page-card-detail-toolbar-button',
                                                        handler: function ()
                                                        {
                                                            //启用工具栏
                                                            toolbar.setDisabled(false);

                                                            //返回一览标签
                                                            card.getLayout().setActiveItem('spms-card-list');
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        );

                        //添加到面板
                        card.add(me._Panel_Edit);
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-edit');

                    //加载数据
                    role_store.load({ params: { 'userID': _CurrentRecord.get('User_ID') } });
                }

                //处理授权按钮点击事件
                function OnAuthorize(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        return;
                    }

                    //获得当前对象
                    var me = this;

                    //判断窗体是否已经初始化
                    if (typeof me._Panel_Authorize == 'undefined')
                    {
                        //创建新增面板
                        me._Panel_Authorize = Ext.create
                        (
                            'Ext.panel.Panel',
                            {
                                layout: 'fit',
                                bodyPadding: '12 6 12 6',
                                id: 'spms-card-authorize',
                                cls: 'spms-page-card-detail',
                                bodyCls: 'spms-page-card-body',
                                border: false,
                                header:
                                {
                                    title: '账户授权',
                                    border: false,
                                    height: 36,
                                    cls: 'spms-page-card-detail-header'
                                },
                                dockedItems:
                                [
                                    {
                                        xtype: 'toolbar',
                                        dock: 'bottom',
                                        ui: 'footer',
                                        cls: 'spms-page-card-detail-toolbar',
                                        padding: '15 0 3 0',
                                        items:
                                        [
                                            '->',
                                            {
                                                text: '确定',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function ()
                                                {
                                                    //用于记录需要提交的数据
                                                    var postParams = [];

                                                    //循环收集需要提交的数据
                                                    for (var index = 0; index < role_store.getCount() ; index++)
                                                    {
                                                        //获得记录
                                                        var model = role_store.getAt(index);

                                                        //判断是否设置了权限
                                                        if (model.get('IsAssigned'))
                                                        {
                                                            //添加模型
                                                            postParams.push(model.get('Role_ID'));
                                                        }
                                                    }

                                                    //创建要提交的数据
                                                    var jsonData = { User_ID: _CurrentRecord.get('User_ID'), LoginName: _CurrentRecord.get('LoginName'), Roles: postParams };

                                                    //创建请求对象
                                                    Ext.Ajax.request
                                                    (
                                                        {
                                                            url: spms.url.Action('Authorize', 'Account'),
                                                            method: spms.constant.HttpMethod.POST,
                                                            jsonData: jsonData,
                                                            callback: function (options, success, response)
                                                            {
                                                                //处理错误
                                                                if (spms.exception.HandleAjaxRequestError(options, success, response))
                                                                {
                                                                    //启用工具栏
                                                                    toolbar.setDisabled(false);

                                                                    //返回一览标签
                                                                    card.getLayout().setActiveItem('spms-card-list');
                                                                }
                                                            }
                                                        }
                                                    );
                                                }
                                            },
                                            {
                                                text: '取消',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function ()
                                                {
                                                    //启用工具栏
                                                    toolbar.setDisabled(false);

                                                    //返回一览标签
                                                    card.getLayout().setActiveItem('spms-card-list');
                                                }
                                            }
                                        ]
                                    }
                                ],
                                items:
                                [
                                    {
                                        xtype: 'grid',
                                        store: role_store,
                                        draggable: false,
                                        stateful: false,
                                        cls: 'spms-grid',
                                        border: true,
                                        forceFit: true,
                                        autoScroll: true,
                                        columnLines: true,
                                        viewConfig:
                                        {
                                            stripeRows: true,
                                            loadingText: spms.resources.text_loading,
                                            singleSelect: true
                                        },
                                        columns:
                                        [
                                            {
                                                text: '授予状态',
                                                width: 80,
                                                minWidth: 80,
                                                sortable: true,
                                                xtype: 'checkcolumn',
                                                dataIndex: 'IsAssigned',
                                                hideable: false,
                                                align: 'center'
                                            },
                                            {
                                                text: '角色显示名',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Title',
                                                hideable: false
                                            },
                                            {
                                                text: '角色参照名',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Name',
                                                hideable: false
                                            },
                                            {
                                                text: '角色说明',
                                                width: 200,
                                                minWidth: 120,
                                                sortable: true,
                                                align: 'left',
                                                dataIndex: 'Role_Desc',
                                                hideable: false,
                                                flex: 1
                                            }
                                        ]
                                    }
                                ]
                            }
                        );

                        //添加到面板
                        card.add(me._Panel_Authorize);
                    }

                    //禁用工具栏
                    toolbar.setDisabled(true);

                    //切换到面板
                    card.getLayout().setActiveItem('spms-card-authorize');

                    //加载数据
                    role_store.load({ params: { 'userID': _CurrentRecord.get('User_ID') } });
                }

                //处理状态变更按钮点击事件
                function OnChangeState(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        return;
                    }

                    //用于保存提示消息
                    var msg = '';

                    //判断是否启用
                    if (_CurrentRecord.get('IsEnabled'))
                    {
                        //设置提示信息
                        msg = msg.concat('确定要停用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦停用，则无法使用该账号登陆系统。')
                    }
                    else
                    {
                        //设置提示信息
                        msg = msg.concat('确定要启用选中的账户"', _CurrentRecord.get('LoginName'), '"吗？<br\><br\>注意：账户一旦启用，则可以使用该账号登陆系统。')
                    }

                    //创建参数
                    var options =
                    {
                        msg: msg,
                        maskTarget: grid,
                        mask: spms.resources.text_submitting,
                        url: spms.url.Action('ChangeState', 'Account'),
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //处理状解锁按钮点击事件
                function OnUnlock(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        return;
                    }

                    //创建参数
                    var options =
                    {
                        msg: ''.concat('确定要解除选中账户"', _CurrentRecord.get('LoginName'), '"的锁定状态吗？'),
                        url: spms.url.Action('Unlock', 'Account'),
                        maskTarget: grid,
                        mask: spms.resources.text_submitting,
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //处理状解锁按钮点击事件
                function OnResetPassword(sender)
                {
                    //判断是否选中记录
                    if (!spms.common.IsValid(_CurrentRecord))
                    {
                        return;
                    }

                    //创建参数
                    var options =
                    {
                        msg: ''.concat('确定要重置选中账户"', _CurrentRecord.get('LoginName'), '"的登陆密码吗？<br\><br\>注意：账户的登陆密码一旦重置，则该账户下次登陆系统时必须修改登陆密码。'),
                        url: spms.url.Action('ResetPassword', 'Account'),
                        maskTarget: grid,
                        mask: spms.resources.text_submitting,
                        params: _CurrentRecord.data,
                        callback: OnAjaxRequestCallback
                    }

                    //执行请求
                    spms.common.DoAjaxRequestWithConfirm(options);
                }

                //Ajax回调
                function OnAjaxRequestCallback(options)
                {
                    //刷新数据
                    Refresh();
                }

                //刷新数据
                function Refresh(options)
                {
                    //刷新数据
                    store.load(options);
                }

                //处理表格行选中事件
                function OnRowSelect(panel, record, index, options)
                {
                    //记录当前选中记录
                    _CurrentRecord = record;

                    //更新按钮状态
                    UpdateButtonState(record);
                }

                //上传文件
                function UploadFile(panel)
                {
                    //上传文件
                    spms.common.UploadFile
                    (
                        {
                            file_types: '*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif',
                            file_types_description: 'Image Files(*.bmp;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif)',
                            file_size_limit: '2 MB',
                            file_size_limit_tip: '小于2MB的图片文件',
                            callback: OnUploadImageCallback,
                            _Panel: panel
                        }
                    );
                }

                //图片上传完成回调
                function OnUploadImageCallback(response, options)
                {
                    //判断是否成功
                    if (!response.success)
                    {
                        //直接返回
                        return;
                    }

                    //获得面板
                    var panel = options._Panel;

                    //获得上传文件编号
                    if (response.data && response.data.length > 0 && panel)
                    {
                        //获得文件编号
                        var tempFileID = response.data[0];

                        //获得字段
                        var txtHasSignature = panel.down('#HasSignature');
                        var txtSignatureID = panel.down('#Signature_ID');
                        var panelSignaturePreview = panel.down('#SignaturePreview');

                        //更新值
                        txtHasSignature.setValue(true);
                        txtSignatureID.setValue(tempFileID);

                        //用于保存参数
                        var params =
                        [
                            { Name: 'FileID', Value: tempFileID },
                            { Name: 'Format', Value: 'png' },
                            { Name: 'Width', Value: panelSignaturePreview.maxWidth },
                            { Name: 'Height', Value: panelSignaturePreview.maxHeight }
                        ];

                        //获得图片地址
                        var imageUrl = spms.url.Action('GetTempImage', 'Common', params);

                        //显示预览图
                        panelSignaturePreview.setSrc(imageUrl);
                    }
                }

                //执行新增操作
                function DoAdd(isContinuousNew)
                {
                    //获得当前对象
                    var me = this;

                    //获得表单
                    var form = me._Panel_Create.down('form');

                    //获得存储对象
                    var storeRoles = me._Role_Store;

                    //用于记录需要提交的数据
                    var postParams = [];

                    //循环收集需要提交的数据
                    for (var index = 0; index < storeRoles.getCount() ; index++)
                    {
                        //获得记录
                        var model = storeRoles.getAt(index);

                        //判断是否设置了权限
                        if (model.get('IsAssigned'))
                        {
                            //添加模型
                            postParams.push(model.get('Role_ID'));
                        }
                    }

                    //判断表单是否有效
                    if (form)
                    {
                        //获得表单对象
                        var formBase = form.getForm();

                        //检查数据是否合法
                        if (formBase.isValid())
                        {
                            //提交数据
                            formBase.submit
                            (
                                {
                                    url: spms.url.Action('Create', 'Account'),
                                    method: spms.constant.HttpMethod.Post,
                                    params: { Roles: postParams },
                                    submitEmptyText: false,
                                    waitTitle: spms.resources.text_submitting_title,
                                    waitMsg: spms.resources.text_submitting,
                                    success: function (panel, action)
                                    {
                                        //处理提交错误
                                        if (spms.exception.HandleSuccessError(panel, action))
                                        {
                                            //判断是否连续新增
                                            if (isContinuousNew)
                                            {
                                                //重置表单
                                                panel.reset();

                                                //设置焦点
                                                form.down('field').focus(false, 50);
                                            }
                                            else
                                            {
                                                //启用工具栏
                                                toolbar.setDisabled(false);

                                                //返回一览标签
                                                card.getLayout().setActiveItem('spms-card-list');

                                                //刷新数据
                                                Refresh();
                                            }
                                        }
                                    },
                                    failure: spms.exception.HandleFailureError
                                }
                            );
                        }
                    }
                }
            }
        );
    </script>
}

